#***********************************************************
#
# Makefile
#
#***********************************************************
export MAKE_PATH := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
ifeq (env.h, $(wildcard env.h))
include $(MAKE_PATH)/env.h
endif
include $(MAKE_PATH)/env/make.env
include $(MAKE_PATH)/make.path
include $(MAKE_PATH)/make.rule
include $(MAKE_PATH)/make.cfg

.PHONY: menuconfig all sdk cli

menuconfig:
ifeq ($(COMPILE_SYS), Cygwin)
	${MENU_CONFIG_TOOL_PATH}/mconf ${MENU_CONFIG_TOOL_PATH}/config_scripts/Kconfig
else
	${MENU_CONFIG_TOOL_PATH}/lnxmconf ${MENU_CONFIG_TOOL_PATH}/config_scripts/Kconfig
endif

	${ECHO} "export SDK_BASE_PATH="`cd ../;pwd` > env.h
	${CAT} .config | sed 's/^[^#]/export &/g' >> env.h
	sed -i 's/=y/=YES/g' env.h
	sed -i 's/CONFIG_//g' env.h
	sed -i 's/\"//g' env.h

all:
	make -j $(nproc) -f make.target all_target

sdk:
	make -f make.target sdk_target

cli:
	make -f make.target cli_target

RELEASE_VERSION = `awk -F '"' '/YT_SDK_VERSION/' ${SDK_BASE_PATH}/version.h | cut -f2 -d'"'`
release:sdk
ifneq (${YT_SDK_VERSION},)
	sed -i 's/\(YT_SDK_VERSION \).*/\1\"${YT_SDK_VERSION}\"/' ${SDK_BASE_PATH}/version.h
endif
	mv libsdk.so ../release/sdk_${RELEASE_VERSION}.so

clean:
	make -f make.target clean
